package org.jim.server.demo.service;

import org.jim.core.packets.Command;
import org.jim.server.command.CommandManager;
import org.jim.server.command.handler.ChatReqHandler;
import org.jim.server.command.handler.HandshakeReqHandler;
import org.jim.server.command.handler.LoginReqHandler;
import org.jim.server.demo.command.WebWsHandshakeProcessor;
import org.jim.server.processor.MultiProtocolCmdProcessor;
import org.jim.server.processor.SingleProtocolCmdProcessor;
import org.jim.server.processor.chat.BaseAsyncChatMessageProcessor;
import org.jim.server.protocol.AbstractProtocolCmdProcessor;

public enum TransformHandler {

    INIT;

    public static void setHandler(Object object){

        if(object instanceof WebWsHandshakeProcessor){
            HandshakeReqHandler handshakeReqHandler = CommandManager.getCommand(Command.COMMAND_HANDSHAKE_REQ, HandshakeReqHandler.class);
            //添加自定义握手处理器;
            handshakeReqHandler.addMultiProtocolProcessor((MultiProtocolCmdProcessor) object);
        }else if(object instanceof AbstractProtocolCmdProcessor){
            LoginReqHandler loginReqHandler = CommandManager.getCommand(Command.COMMAND_LOGIN_REQ, LoginReqHandler.class);
            //添加登录业务处理器;
            loginReqHandler.setSingleProcessor((SingleProtocolCmdProcessor) object);
        }else if(object instanceof BaseAsyncChatMessageProcessor){
            //添加用户业务聊天记录处理器，用户自己继承抽象类BaseAsyncChatMessageProcessor即可，以下为内置默认的处理器！
            ChatReqHandler chatReqHandler = CommandManager.getCommand(Command.COMMAND_CHAT_REQ, ChatReqHandler.class);
            chatReqHandler.setSingleProcessor((SingleProtocolCmdProcessor) object);
        }
    }
}
